package com.yearno.baseframe.base

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.fragment.app.DialogFragment
import com.yearno.baseframe.R
import java.lang.ref.WeakReference

/**
 * Created by cxf on 2018/9/29.
 */
abstract class BaseDialogFragment : DialogFragment() {
    private var mContext: Context? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        Log.d("NBaseDialogFragment", "onCreate")
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_FRAME, R.style.Base_Theme_CommonDialog)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        Log.d("NBaseDialogFragment", "onCreateView")
        mContext = WeakReference(activity).get()
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
        this.isCancelable = canCancel
        dialog?.setCanceledOnTouchOutside(canCancel)
        return inflater.inflate(layoutId, container)
    }

    override fun onStart() {
        Log.d("NBaseDialogFragment", "onStart")
        super.onStart()
        setWindowAttributes(dialog?.window)
    }

    protected abstract val layoutId: Int
    protected abstract val canCancel: Boolean
    protected abstract fun setWindowAttributes(window: Window?)

}